package study.async.springboot.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.async.springboot.service.AsyncService;
import study.eggs.result.Result;
import study.eggs.result.Results;

/**
 * 1.注解 @Async 需要 @EnableAsync 开启支持，否则 @Async 无效
 * 2.不等待异步执行，直接返回给调用方
 */
@Slf4j
@RestController
public class _2_AsyncController {

    @Autowired
    private AsyncService asyncService;

    @RequestMapping("/async")
    public Result async() {
        log.info(">>>>>> i am controller");
        asyncService.doAsync(3);
        return Results.ok();
    }
}
